using System;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using UnityEngine;

public class GameManager : NetworkBehaviour
{
    public UnityTransport unityTransport;

    void Awake() {
        
    }

    private void Start() {
        Debug.Log("NetworkManager is " + NetworkManager.Singleton);
        if(NetworkManager.Singleton != null) {
            if(Application.isBatchMode) {
                NetworkManager.Singleton.StartServer();
                Debug.Log("服务器模式启动成功,主机IP: " + unityTransport.ConnectionData.Address + " 端口：" + unityTransport.ConnectionData.Port);
                NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallback;
            } else {
                // NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData("10.0.0.232",(ushort)7777);
            }
        }
    }

    private void OnClientConnectedCallback(ulong obj)
    {
        Debug.Log("client obj is " + obj);
    }


    public override void OnNetworkSpawn()
    {
        Debug.Log("GameManager newworkSpawn");
        
    }
}
